﻿using System;
using System.Linq;

namespace Twitter
{
    class ErrorMessageSender
    {
        public static void SendProcessingErrorMessage(IBotClient client, Message errorSourceMessage, IMessageProcessor processor, Exception ex)
        {
            IMessageBuilder messageBuilder = new PlainTextMessageBuilder();
            messageBuilder.Clear();
            messageBuilder.AppendFragment(string.Format("Your message '{0}' was understood but I could not process it. Sorry :-(",errorSourceMessage.Text));
            TwitterMessageLogger.AddLog(errorSourceMessage.Text, messageBuilder.GetMessages().Aggregate((a,b) => a + b), processor.GetType().Name, ex, errorSourceMessage.Sender.Name);
            client.SendMessages(errorSourceMessage.Sender.ScreenName, messageBuilder.GetMessages());
        }
    }
}
